#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/sched.h>
#include <linux/slab.h>

#define WMARK_NAME	"wmarklookback"

enum wmark_state {
	wmark_STATE_UNKNOWN,
	wmark_STATE_REGISTERED,
};

struct wmark_device {
	struct mutex		mutex;
	enum wmark_state	state;
};

static struct miscdevice wmark_misc;

static int wmark_open(struct inode *inode, struct file *file)
{
	struct wmark_device *udev;

	udev = kzalloc(sizeof(*udev), GFP_KERNEL);
	if (!udev)
		return -ENOMEM;


	file->private_data = udev;
	return 0;
}

static ssize_t wmark_write(struct file *file, const char __user *buffer,
			   size_t count, loff_t *ppos)
{
	//struct wmark_device *udev = file->private_data;

	return 0;
}

static ssize_t wmark_read(struct file *file, char __user *buffer, size_t count,
			  loff_t *ppos)
{
	//struct wmark_device *udev = file->private_data;
	return 0;
}

static __poll_t wmark_poll(struct file *file, poll_table *wait)
{
	//struct wmark_device *udev = file->private_data;

	return 0;
}

static int wmark_release(struct inode *inode, struct file *file)
{
	struct wmark_device *udev = file->private_data;

	kfree(udev);

	return 0;
}

static const struct file_operations wmark_fops = {
	.owner		= THIS_MODULE,
	.open		= wmark_open,
	.release	= wmark_release,
	.read		= wmark_read,
	.write		= wmark_write,
	.poll		= wmark_poll,
	.llseek		= no_llseek,
};

static struct miscdevice wmark_misc = {
	.fops		= &wmark_fops,
	.minor		= MISC_DYNAMIC_MINOR,
	.name		= WMARK_NAME,
};

static int __init wmark_init(void)
{
	return misc_register(&wmark_misc);
}
module_init(wmark_init);

static void __exit wmark_exit(void)
{
	misc_deregister(&wmark_misc);
}
module_exit(wmark_exit);

MODULE_AUTHOR("Leo <binxin.cao@megatronix.co>");
MODULE_DESCRIPTION("Water Mark Lookback Driver.");
MODULE_LICENSE("GPL");
